import argparse
from generators import (
    FileGenerator,
    TemplateGenerator,
    TableGenerator
)
import pandas as pd
from datetime import datetime

def generate_readme_example():
    """生成标准README示例[6,7](@ref)"""
    context = {
        "project_name": "MiniBox Pro",
        "description": "多功能数据分析工具",
        "installation": [
            "pip install -r requirements.txt",
            "python main.py --config config.yaml"
        ],
        "usage_examples": [
            "python main.py analyze data.csv",
            "python main.py search --keyword '北京'"
        ],
        "authors": ["DataTeam"],
        "license": "MIT"
    }
    
    TemplateGenerator().render_template(
        "readme_template.md",
        context,
        "README.md"
    )

if __name__ == "__main__":
    parser = argparse.ArgumentParser(description="Markdown生成工具")
    subparsers = parser.add_subparsers(dest='command')
    
    # 目录结构生成命令
    struct_parser = subparsers.add_parser('struct', help='生成目录结构')
    struct_parser.add_argument('path', help='要扫描的目录路径')
    
    # 模板生成命令
    template_parser = subparsers.add_parser('template', help='使用模板生成')
    template_parser.add_argument('template', help='模板文件名')
    template_parser.add_argument('--output', default='output.md', help='输出路径')
    
    args = parser.parse_args()
    
    if args.command == 'struct':
        print("正在生成目录结构...")
        FileGenerator.generate_file_structure(args.path)
    elif args.command == 'template':
        print("正在渲染模板...")
        sample_data = {
            "title": "月度报告",
            "generation_time": datetime.now().strftime("%Y-%m-%d"),
            "total_records": 1500,
            "summary_table": TableGenerator.generate_from_dataframe(
                pd.DataFrame({
                    '指标': ['平均值', '最大值'],
                    '数值': [85.6, 99.3]
                })
            )
        }
        TemplateGenerator().render_template(
            args.template,
            sample_data,
            args.output
        )
    else:
        generate_readme_example()